#!/usr/bin/env python
"""This module loads configuration data """
import os
import ConfigParser

class Config:
    def __init__(self, fileName=None):
        if fileName:
            self.loadIni(fileName)
        else:
            self.loadDefaults()
    
    def loadDefaults(self):
        self.dataFolder = 'data'
        self.pluginFolder = 'plugins'
        
        #Dynamics
        self.collideAgainstStaticFlag = True
        self.collideAgainstDynamicFlag = False
        
        #Interface
        self.theme = 'default'
        self.locale = 'en-US'
    
    def loadIni(self, fileName):
        filePath = os.path.abspath(fileName)
        parser = cfg = ConfigParser.ConfigParser()
        parser.readfp(open(filePath))
        
        #Main
        self.dataFolder = cfg.get('Main', 'dataFolder')
        self.pluginFolder = cfg.get('Main', 'pluginFolder')
        
        #Dynamics
        self.collideAgainstStaticFlag = cfg.getboolean('Dynamics',
                                                    'collideAgainstStaticFlag')
        self.collideAgainstDynamicFlag = cfg.getboolean('Dynamics',
                                                   'collideAgainstDynamicFlag')
        
        #Interface
        self.theme = cfg.get('Interface', 'theme')
        self.locale = cfg.get('Interface', 'locale')